package spring.JUNIT.Resource;

import java.io.IOException;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.io.Resource;

public class zzyResource implements ApplicationContextAware {

	private ApplicationContext applicationContext;

	@Override
	public void setApplicationContext(ApplicationContext applicationContext)
			throws BeansException {
		// TODO Auto-generated method stub
		this.applicationContext = applicationContext;

	}

	public void resouce() {// 不加前缀默认取 applicationContext的前缀
		Resource resource = applicationContext
				.getResource("file:D:\\software\\myproject\\workplace\\z-spring\\src\\JUNIT\\Resource\\config.txt");
		System.out.println(resource.getFilename());
		try {
			System.out.println(resource.contentLength());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		resource = applicationContext
				.getResource("url:http://www.58pic.com/shipin/17394370.html");
		try {
			System.out.println(resource.getFilename());
			System.out.println(resource.contentLength());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
